import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const CStore = defineStore('counter', () => {
 /*  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  } */
 

  // 最近被点击城市信息
  const clickCity = ref(['哈瓦','卡萨','拉萨'])

  const piniaCities = ref({})



   // 本地城市信息
   const locationCity = ref({
    name:'',
    location:[],
    adcode:''
   })

 

  //  当前选择城市信息初始化方法
  const getDefaultCity = ()=> {
      const currentCityDate = ref({
        name:'',
        location:[],
        adcode:''
      })

      if(localStorage.getItem("currentCityData")) {
        currentCityDate.value = JSON.parse(localStorage.getItem("currentCityData")) 
      }
      return currentCityDate
    }

     // 当前选择城市的信息
    const currentCityDate = getDefaultCity()
  // 为currentCityData设置值的函数
  const changeCurrentCity = (n,l,a)=>{
    currentCityDate.value = {
        name:n,
        location:l,
        adcode:a
    }
    localStorage.setItem("currentCityData", JSON.stringify( currentCityDate.value));
  }

  // 城市天气信息
  const cityWeatherDate = ref({
    temp:'',//温度
    icon:'',//天气图标
    text:'',//天气
    windDir:'',//风向
    windSpeed:'',//风速
    windScale:'',//风力等级
    humidity:'',//相对湿度
  })

  // 修改城市天气信息
  function setWeatherDate(
    temp,
    icon,
    text,
    windDir,
    windSpeed,
    windScale,
    humidity,
  ) {
    cityWeatherDate.value.temp=temp
    cityWeatherDate.value.icon=icon
    cityWeatherDate.value.text=text
    cityWeatherDate.value.windDir=windDir
    cityWeatherDate.value.windSpeed=windSpeed
    cityWeatherDate.value.windScale=windScale
    cityWeatherDate.value.humidity=humidity
  }

  return {locationCity,clickCity,piniaCities,currentCityDate,cityWeatherDate,setWeatherDate,changeCurrentCity}
})
